﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data;
using BangleCMS.DBUtility;

namespace BangleCMS.DAL
{
    /// <summary>
    /// 数据访问类:t_newsDAL
    /// </summary>
    public partial class t_knowledgeDAL
    {
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BangleCMS.Model.t_knowledge GetLastModel(int KnowledgeId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select KnowledgeId,Title,Keywords,Description,ReleaseDate,Source,Author,NewsType,Abstract,Content,ReadCount,OrderNo,Top,CreateUser,CreateDate,UpdateUser,UpdateDate,Valid from t_knowledge ");
            strSql.Append(" where KnowledgeId>@KnowledgeId LIMIT 0,1");
            MySqlParameter[] parameters = {
					new MySqlParameter("@KnowledgeId", MySqlDbType.Int32)
			};
            parameters[0].Value = KnowledgeId;

            BangleCMS.Model.t_knowledge model = new BangleCMS.Model.t_knowledge();
            DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["KnowledgeId"] != null && ds.Tables[0].Rows[0]["KnowledgeId"].ToString() != "")
                {
                    model.KnowledgeId = int.Parse(ds.Tables[0].Rows[0]["KnowledgeId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Title"] != null && ds.Tables[0].Rows[0]["Title"].ToString() != "")
                {
                    model.Title = ds.Tables[0].Rows[0]["Title"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Keywords"] != null && ds.Tables[0].Rows[0]["Keywords"].ToString() != "")
                {
                    model.Keywords = ds.Tables[0].Rows[0]["Keywords"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Description"] != null && ds.Tables[0].Rows[0]["Description"].ToString() != "")
                {
                    model.Description = ds.Tables[0].Rows[0]["Description"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ReleaseDate"] != null && ds.Tables[0].Rows[0]["ReleaseDate"].ToString() != "")
                {
                    model.ReleaseDate = DateTime.Parse(ds.Tables[0].Rows[0]["ReleaseDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Source"] != null && ds.Tables[0].Rows[0]["Source"].ToString() != "")
                {
                    model.Source = ds.Tables[0].Rows[0]["Source"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Author"] != null && ds.Tables[0].Rows[0]["Author"].ToString() != "")
                {
                    model.Author = ds.Tables[0].Rows[0]["Author"].ToString();
                }
                if (ds.Tables[0].Rows[0]["NewsType"] != null && ds.Tables[0].Rows[0]["NewsType"].ToString() != "")
                {
                    model.NewsType = ds.Tables[0].Rows[0]["NewsType"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Abstract"] != null && ds.Tables[0].Rows[0]["Abstract"].ToString() != "")
                {
                    model.Abstract = ds.Tables[0].Rows[0]["Abstract"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Content"] != null && ds.Tables[0].Rows[0]["Content"].ToString() != "")
                {
                    model.Content = ds.Tables[0].Rows[0]["Content"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ReadCount"] != null && ds.Tables[0].Rows[0]["ReadCount"].ToString() != "")
                {
                    model.ReadCount = int.Parse(ds.Tables[0].Rows[0]["ReadCount"].ToString());
                }
                if (ds.Tables[0].Rows[0]["OrderNo"] != null && ds.Tables[0].Rows[0]["OrderNo"].ToString() != "")
                {
                    model.OrderNo = int.Parse(ds.Tables[0].Rows[0]["OrderNo"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Top"] != null && ds.Tables[0].Rows[0]["Top"].ToString() != "")
                {
                    model.Top = int.Parse(ds.Tables[0].Rows[0]["Top"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CreateUser"] != null && ds.Tables[0].Rows[0]["CreateUser"].ToString() != "")
                {
                    model.CreateUser = int.Parse(ds.Tables[0].Rows[0]["CreateUser"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CreateDate"] != null && ds.Tables[0].Rows[0]["CreateDate"].ToString() != "")
                {
                    model.CreateDate = DateTime.Parse(ds.Tables[0].Rows[0]["CreateDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UpdateUser"] != null && ds.Tables[0].Rows[0]["UpdateUser"].ToString() != "")
                {
                    model.UpdateUser = int.Parse(ds.Tables[0].Rows[0]["UpdateUser"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UpdateDate"] != null && ds.Tables[0].Rows[0]["UpdateDate"].ToString() != "")
                {
                    model.UpdateDate = DateTime.Parse(ds.Tables[0].Rows[0]["UpdateDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Valid"] != null && ds.Tables[0].Rows[0]["Valid"].ToString() != "")
                {
                    model.Valid = int.Parse(ds.Tables[0].Rows[0]["Valid"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BangleCMS.Model.t_knowledge GetNextModel(int KnowledgeId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select KnowledgeId,Title,Keywords,Description,ReleaseDate,Source,Author,NewsType,Abstract,Content,ReadCount,OrderNo,Top,CreateUser,CreateDate,UpdateUser,UpdateDate,Valid from t_knowledge ");
            strSql.Append(" where KnowledgeId<@KnowledgeId LIMIT 0,1");
            MySqlParameter[] parameters = {
					new MySqlParameter("@KnowledgeId", MySqlDbType.Int32)
			};
            parameters[0].Value = KnowledgeId;

            BangleCMS.Model.t_knowledge model = new BangleCMS.Model.t_knowledge();
            DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["KnowledgeId"] != null && ds.Tables[0].Rows[0]["KnowledgeId"].ToString() != "")
                {
                    model.KnowledgeId = int.Parse(ds.Tables[0].Rows[0]["KnowledgeId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Title"] != null && ds.Tables[0].Rows[0]["Title"].ToString() != "")
                {
                    model.Title = ds.Tables[0].Rows[0]["Title"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Keywords"] != null && ds.Tables[0].Rows[0]["Keywords"].ToString() != "")
                {
                    model.Keywords = ds.Tables[0].Rows[0]["Keywords"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Description"] != null && ds.Tables[0].Rows[0]["Description"].ToString() != "")
                {
                    model.Description = ds.Tables[0].Rows[0]["Description"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ReleaseDate"] != null && ds.Tables[0].Rows[0]["ReleaseDate"].ToString() != "")
                {
                    model.ReleaseDate = DateTime.Parse(ds.Tables[0].Rows[0]["ReleaseDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Source"] != null && ds.Tables[0].Rows[0]["Source"].ToString() != "")
                {
                    model.Source = ds.Tables[0].Rows[0]["Source"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Author"] != null && ds.Tables[0].Rows[0]["Author"].ToString() != "")
                {
                    model.Author = ds.Tables[0].Rows[0]["Author"].ToString();
                }
                if (ds.Tables[0].Rows[0]["NewsType"] != null && ds.Tables[0].Rows[0]["NewsType"].ToString() != "")
                {
                    model.NewsType = ds.Tables[0].Rows[0]["NewsType"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Abstract"] != null && ds.Tables[0].Rows[0]["Abstract"].ToString() != "")
                {
                    model.Abstract = ds.Tables[0].Rows[0]["Abstract"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Content"] != null && ds.Tables[0].Rows[0]["Content"].ToString() != "")
                {
                    model.Content = ds.Tables[0].Rows[0]["Content"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ReadCount"] != null && ds.Tables[0].Rows[0]["ReadCount"].ToString() != "")
                {
                    model.ReadCount = int.Parse(ds.Tables[0].Rows[0]["ReadCount"].ToString());
                }
                if (ds.Tables[0].Rows[0]["OrderNo"] != null && ds.Tables[0].Rows[0]["OrderNo"].ToString() != "")
                {
                    model.OrderNo = int.Parse(ds.Tables[0].Rows[0]["OrderNo"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Top"] != null && ds.Tables[0].Rows[0]["Top"].ToString() != "")
                {
                    model.Top = int.Parse(ds.Tables[0].Rows[0]["Top"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CreateUser"] != null && ds.Tables[0].Rows[0]["CreateUser"].ToString() != "")
                {
                    model.CreateUser = int.Parse(ds.Tables[0].Rows[0]["CreateUser"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CreateDate"] != null && ds.Tables[0].Rows[0]["CreateDate"].ToString() != "")
                {
                    model.CreateDate = DateTime.Parse(ds.Tables[0].Rows[0]["CreateDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UpdateUser"] != null && ds.Tables[0].Rows[0]["UpdateUser"].ToString() != "")
                {
                    model.UpdateUser = int.Parse(ds.Tables[0].Rows[0]["UpdateUser"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UpdateDate"] != null && ds.Tables[0].Rows[0]["UpdateDate"].ToString() != "")
                {
                    model.UpdateDate = DateTime.Parse(ds.Tables[0].Rows[0]["UpdateDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Valid"] != null && ds.Tables[0].Rows[0]["Valid"].ToString() != "")
                {
                    model.Valid = int.Parse(ds.Tables[0].Rows[0]["Valid"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }
    }
}
